package com.ethannhu.todaynews.component.main

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.ethannhu.todaynews.component.category.CategoryFragment
import com.ethannhu.todaynews.component.discovery.DiscoveryFragment
import com.ethannhu.todaynews.component.me.MeFragment
import com.ethannhu.todaynews.component.shortvideo.ShortVideoFragment

/**
 * 首页 Adapter
 */
class MainAdapter(fragmentActivity: FragmentActivity, private val count: Int)
    : FragmentStateAdapter(fragmentActivity) {
    override fun getItemCount(): Int {
       return count
    }

    override fun createFragment(position: Int): Fragment {
        return when (position) {
            0 -> DiscoveryFragment.newInstance()
            1 -> ShortVideoFragment.newInstance()
            2 -> CategoryFragment.newInstance()
            else -> MeFragment.newInstance()
        }
    }

}